package nkr1pt.popkorn.download;

import com.google.inject.Inject;
import java.util.logging.Level;
import java.util.logging.Logger;
import nkr1pt.popkorn.download.DownloadCandidate.Host;
import nkr1pt.popkorn.properties.PropertyLoader;

/**
 * Gets cookie(s) from a download service.
 * These cookies are used for authentication to be able
 * to download from a service.
 *
 * @author Kristof Vanhaeren
 */
public class CookieFactory {

    private PropertyLoader propertyLoader;
    private static final Logger logger = Logger.getLogger(CookieFactory.class.getName());

    @Inject
    public CookieFactory(PropertyLoader propertyLoader) {
        this.propertyLoader = propertyLoader;
    }

    public String getCookie(Host host) {
        try {
            switch (host) {
                case RAPIDSHARE:
                    Rapidshare rapidshare = new Rapidshare(propertyLoader);
                    return rapidshare.getCookie();
                default:
                    throw new Exception();
            }
        } catch (Exception e) {
            logger.log(Level.SEVERE, "An exception occurred while trying to get cookie.\n{0}", e.getMessage());
        }

        return null;
    }
}